home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / UUEXE525.ZIP / UUDECODE.DOC next >
Text File  |  1993-12-03  |  17KB  |  382 lines

  1.  
  2. Documentation for UUENCODE/DECODE 5.25
  3.  
  4. UU-encoding is a way to code a file which may contain any characters into a
  5. standard character set that can be reliably sent over diverse networks.
  6.  
  7.  
  8. THE CHARACTER ENCODING:
  9.  
  10. The basic scheme is to break groups of 3 eight bit characters (24 bits) into 4
  11. six bit characters and then add 32 (a space) to each six bit character which
  12. maps it into the readily transmittable character.  Another way of phrasing this
  13. is to say that the encoded 6 bit characters are mapped into the set:
  14.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  15. for transmission over communications lines.
  16.  
  17. As some transmission mechanisms compress or remove spaces, spaces are changed
  18. into back-quote characters (a 96).  (A better scheme might be to use a bias of
  19. 33 so the space is not created, but this is not done.)
  20.  
  21. Another newer less popular encoding method, called XX-encoding uses the set:
  22.         +-01..89ABC...XYZabc...xyz
  23.  
  24. In my opinion, XX-encoding is superior to UU-encoding because it uses more
  25. "normal" characters that are less likely to get corrupted.  In fact several of
  26. the special characters in the UU set do not get thru an EBCDIC to ASCII
  27. translation correctly.  Conversely, an advantage of the UU set is that it does
  28. not use lower case characters.  Now-a-days both upper and lower case are sent
  29. with no problems; maybe in the communications dark ages, there was a problem
  30. with lower case.
  31.  
  32. This "UU" encode/decode pair can handle either XX or UU encoding.  The encode
  33. program defaults to creating a UU encoded file; but can be run with a "-x"
  34. option to create an XX encoding.
  35.  
  36. The decode program defaults to autodetect.  However the program can get confused
  37. by comment lines preceeding the actual encoded data.  The decode mode can be
  38. forced to UU or XX with the "-u" or "-x" parameter.
  39.  
  40. Another option is for the character mapping table to be inserted at the front of
  41. the file.  The format for this is discussed later.  The table parameters are
  42. detected and used by this decode program.  (A table will override the "-x" or
  43. "-u" parameters.) The encode program can be run with a "-t" option which tells
  44. it to put the table into the encoded file.
  45.  
  46. A third encode mapping is the one used by Brad Templeton's ABE program.  This is
  47. not handled by these programs as the check and control information surrounding
  48. the actual encoded data is in a different form.
  49.  
  50. From a theoritical view, this encoding is breaking down 24 bits modulo 64.  Note
  51. that 64**3 is = 2**24.  The result is 24 bits in for 32 bits out, a 33% size
  52. increase.  Note that 85**5 > 2**32.  Also note that there are 94 transmittable
  53. ASCII characters (from 0x21 thru 0x7e).  Thus modulo 85 encoding (the atob
  54. encoder) transforms 32 bits to 5 ASCII chars or 40 bits for a 25% size increase.
  55.  
  56. The trade off in the module 85 encoding is that many communications systems do
  57. not reliably transmit 85 ASCII characters.  The tilda, carat, brackets, and
  58. sometimes upper or lower case frequently get corrupted.
  59.  
  60.  
  61. COMPOSING A LINE OF ENCODED CHARACTERS:
  62.  
  63. A small number of eight bit characters are encoded into a single line and a
  64. count is put at the start of the line.  (Most lines in an encoded file have 45
  65. encoded characters.  When you look at a UU-encoded file note that most lines
  66. start with the letter "M".  "M" is decimal 77 which, minus the 32 bias, is 45.)
  67.  
  68. This encode program puts a check character at the end of each line.  The check
  69. is the sum of all the encoded characters, before adding the mapping, modulo 64.
  70.  
  71. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it uses the
  72. sum of the original, not the encoded characters.  This decode program accepts
  73. either form of line check character.
  74.  
  75. In previous versions (4.13 and lower) the line check characters was generated by
  76. default by this encode program and was supressed with the "-L" option.  One
  77. reason to supress them is if they will be decoded by one of the old Horton
  78. decoders.  Most decoders either accept this form of check or simply stop looking
  79. after the line length is exhausted.  My feelings are mixed about the line
  80. checksums because errors of this type essentially never occur.
  81.  
  82. However with modern, error-free communications systems and with the CRC checks
  83. on the entire file (see below) I have made the default for uuencoding to have NO
  84. line level check characters effective version 4.21.  The "-L" option on uuencode
  85. turns on generation of line checksums.  If you have a really bad communications
  86. system and you want to isolate a problem, turn them on.
  87.  
  88. Uudecode automatically checks for the presense line checksums, so the default
  89. for uudecode is to leave line level checks on; if there are some problems the
  90. "-L" option for uudecode turns them off.  Sometimes there is junk at the end of
  91. the line which causes spurious line checksum errors.
  92.  
  93. I have encountered various other ways that encoders end lines.  One encoder put
  94. a "M" at both the start and end of the line.  Another used a line count
  95. character.  This decode program checks all of these.  I would not be surprised
  96. if some encoder out there ends lines with astrological symbols.  If you
  97. encounter some other wierd form of encoded file, let me know.
  98.  
  99.  
  100. PACKAGING THE LINES INTO FILES:
  101.  
  102. The lines of encoded data can be preceded by comments and by network addressing
  103. information.  The encoded data is directly preceded by a line containing:
  104.  
  105.              begin <file-mode> <file-name>
  106.  
  107. This line is created by the encoding program.  The decode program scans the file
  108. looking for "begin" in column 1.
  109.  
  110. The final end of encoded data is an encoded line with zero encoded characters (a
  111. back-quote), followed by a line containing "end".
  112.  
  113. For integrity checking, various encode programs insert checksums for the entire
  114. file.  This decode tries to check for all known types of file checksums.  This
  115. is discussed in more detail later.
  116.  
  117. This encode program puts a header line, containing the section number and file
  118. name, in front of every section:
  119.  
  120.          "section <number> of uuencode of file <file name>"
  121.  
  122. At the end of a section the encode program inserts a line containing checksum
  123. and file size information.  This can be suppressed with the "-c" option.
  124.  
  125. The transmissions on comp.binaries.ibm.pc contain two different types of section
  126. number/file-name lines.  The first is the "Archive-name line"; the other is the
  127. "part line".
  128.  
  129. The format of the Archive-name line is:
  130.         "Archive-name: <name>/part<number>"
  131. for example:
  132.         Archive-name: diskutl/part02
  133.  
  134. The format of the part line is:
  135.         <name> part<number>/<max-number>
  136. for example:
  137.         diskutl part02/03
  138.  
  139. This program checks for consistency of these names and numbers as of release
  140. 5.0.
  141.  
  142. All the "integrity fields" (the checksum, the line check, and the section header
  143. line) are inserted in a way that they will be ignored by other UUDECODE programs
  144. that cannot handle them.  This decode program does not require any of these
  145. fields; if not present, integrity checking is not done.  This program pair is
  146. 100% downward compatible!
  147.  
  148.  
  149. FILE NAMES:
  150.  
  151. The default name of the file to encode into is the base name of the file you are
  152. encoding plus the ".UUE" extension for UU encoding.
  153.  
  154.         uuencode foo.bar                produces file foo.uue.
  155.  
  156. If the -X (upper case) option is used, then the file will be XXencoded (see
  157. above); and will be saved with the default ".XXE" extension.
  158.  
  159. Uuencode can also be called with a second parameter which is the specific file
  160. name of the encoded file.  If this file name has no extension, the above default
  161. (.UUE or .XXE is used).
  162.  
  163.         uuencode    foo  foo.bar        encode foo to foo.bar
  164.         uuencode -X foo  xxfoo          encode foo to foo.xxe
  165.         uuencode -X foo  xxfoo.bar      encode foo to xxfoo.bar
  166.         uuencode    foo  xxfoo.         encode foo to xxfoo.
  167.  
  168. Uudecode defaults to look for files with the ".UUE" and the ".XXE" extension.
  169. This only applies if uudecode is called without a file name extension:
  170.  
  171.         uudecode    foo         look for file foo.uue, then foo.xxe
  172.         uudecode -u foo         look for file foo.uue only
  173.         uudecode -x foo         look for file foo.xxe, then foo.uue
  174.  
  175. If uudecode is called with a file name extension, then that is used:
  176.  
  177.         uudecode foo.XXX        decode file foo.xxx
  178.         uudecode foo.           decode file foo  with no extension
  179.  
  180.  
  181. SPLITING UP LONG FILES:
  182.  
  183. Long files are broken into several sections before transmission.  This is done
  184. because very large files are cumbersome to handle and because some networks
  185. require files to be less than 64K bytes.
  186.  
  187. This encode program automatically breaks large encoded files into sections.
  188. This split is controlled by several options.  First the "-s" option tells encode
  189. not to split the file.  The "-s nnn" option tells encode to split the file into
  190. hunks of "nnn" lines.  The default is 950 lines which is about 59k.  Sometimes
  191. extensive comments are put into the first file; thus it may be necessary for the
  192. first file to contain fewer encoded lines.  The "-h nnn" option tells encode to
  193. leave room for "nnn" additional lines in the first file.
  194.  
  195. If the data file being encoded is called FOO.ZIP, then the encode program names
  196. the encoded files FOO1.UUE, FOO2.UUE, etc.  (Or .XXE if the -X option is used.)
  197.  
  198. The decode program searches for the various sections, scans over preliminary
  199. comments and decodes all as if they were one big file.  Decode is passed the
  200. base file name "FOO".
  201.  
  202. UUdecode can (but rarely does) get confused and thinks header lines are encoded
  203. data.  Sometimes this is because the seperator line between sections (the "cut"
  204. line) is indistinguishable from valid decodable data.  (An example is the line
  205. "---" used as a cut line on several DOS BBS systems.)  You can tell UUdecode that
  206. a specific line is a cut line and not a decodable line with the -Z option:
  207.  
  208.     uudecode -Z "---" myfile
  209.  
  210. Other times there is not cut line in between file sections or there is some
  211. other problem with the file.  If so, edit the file and try again.  This has only
  212. happened once to me and I have decoded a lot of files.
  213.  
  214. When decode encounters a premature end-of-file or some data which is not
  215. decodable, it assumes the end of a file section.  Decode is conservative when it
  216. encounters data it cannot decode (better an error than a bad file).
  217.  
  218. Usually this undecodable data is valid "trailer" data put at the end of file for
  219. data transmission purposes.  However the file may be bad.  So decode continues
  220. to scan the file, if decode then encounters a line which is decodable it assumes
  221. the file is bad.  Or if there are more than 30 lines remaining in the file,
  222. decode assumes the file is bad.
  223.  
  224. When decode encounters a valid end of file section it must get the next file in
  225. sequence.  If the file name ends with a number, decode tries the next file name
  226. in numeric sequence.  Otherwise decode asks for a file name.  If this file does
  227. not contain decodable data, decode asks for another file to try.
  228.  
  229. If multiple sections are saved in a single file, the sections must have one of
  230. the three (above) types of section header lines for validation.  Decode builds a
  231. table of section information so it can go back and reread if sections are not
  232. saved in order.
  233.  
  234. The "SECTION" line inserted by the UUENCODE program is used for validity
  235. checking only.  If not present, decode will accept any file containing encoded
  236. lines.
  237.  
  238.  
  239. OTHER FILE FORMS:
  240.  
  241. Sometimes files are wrapped in shell archives that automatically check
  242. sequencing and call uudecode for you on Unix systems.  If you prefer to download
  243. the raw files to MS-DOS, uudecode 5.25 will filter simple shell scripts, that
  244. use the Unix 'sed' command, and decode the data automatically.
  245.  
  246. There is one more rarely used feature of ENCODE: many input files can be encoded
  247. into one large encode file.  (I have never seen this used.) The end of an input
  248. file is a zero length encoded line, followed by another "begin" line instead of
  249. by an "end" line.  This decode program will decode this sort of file; but the
  250. encode will only handle a single input file.
  251.  
  252.  
  253. FILE LEVEL CHECKSUMS:
  254.  
  255. There are three types of file checksums found in encoded files:
  256.  
  257.        UUENCODE 2.14 and below inserted lines that gave the section
  258.        size and the original input file size.  This is supplanted
  259.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  260.        and validates the old form
  261.  
  262.        UUENCODE 3.07 and Rahul Dhesi's encode scripts compute a Unix
  263.        "sum -r" on the encoded sections and on the original input file.
  264.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  265.        and size at the end of a file while Rahul''s scripts put them at
  266.        begining.  This UUDECODE analyzes either.
  267.  
  268.        The third form of checksum is a full 32 bit CRC that Rahul's script
  269.        inserts.  My code does not handle this.  Rahul has written the
  270.        BRIK program to check them.  If there is a "sum -r" failure, BRIK
  271.        analysis should be considered.
  272.  
  273. Unisys Unix platforms put a line containing just the original file size at the
  274. end of the encoded file.  My code checks this.
  275.  
  276.  
  277. TABLE LINES:
  278.  
  279. Some encoded files but the mapping used at the front of the encoded file, just
  280. in front of the "begin" line.  The format for this is:
  281.  
  282.                    table
  283.                    first 32 characters
  284.                    second 32 characters
  285.  
  286. All this starts in column 1.
  287.  
  288. If decode encounters a table specification, it uses it and overrides any command
  289. line parameters.  Encode will create the table lines if run with the "-t"
  290. parameter.
  291.  
  292.  
  293. COMPLETION CODES:
  294.  
  295. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are any
  296. problems, ERRORLEVEL is set to non-zero.
  297.  
  298. Most of the options to UUDECODE are obvious.  However, the "-e" option needs
  299. more explanation.  The purpose of "-e" is to automatically run an un-archiver
  300. (like ZOO or PKUNPAK) when UUDECODE successfully completes.  If the "-e" option
  301. is given, UUDECODE calls BAT file UNARCUUE on successful completion; UNARCUUE
  302. is passed five parameters:
  303.  
  304.                 the filename decoded (with path but no extension),
  305.                 the file extension,
  306.                 the input file name  (with path but no extension),
  307.                 the input file extension that is used,
  308.                 the number of sections.
  309.  
  310. Normally the file extension tells which un-archiver to call.  The UNARCUUE BAT
  311. file, can test these parameters and call the necessary un-archiver.  If
  312. UNARCUUE is called, the return code from UUDECODE is the return code passed
  313. back from UNARCUUE.  One user had a problem in that the routines called by
  314. UNARCUUE set the errorlevel to 1 which was passed back to be the return code
  315. from UUDECODE.
  316.  
  317.  
  318. This works well for me.  On UNIX I find a program I want in three sections:
  319.               PRG1, PRG2, PRG3.
  320. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  321. then just enter UUDECODE PRG and the thing decodes.
  322.  
  323.  
  324. Done privately and not for profit (freeware).  Suggestions appreciated.
  325. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.  The
  326. source is not public domain.  I would entertain consulting contracts for porting
  327. to other hardware platforms.  Also if included in your for profit product,
  328. please contact me.
  329.  
  330.  
  331. Richard Marks
  332. 931 Sulgrave Lane
  333. Bryn Mawr, PA 19010
  334.  
  335. Copyright Richard E. Marks, Bryn Mawr, PA, 1992
  336.  
  337. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  338.  
  339. Change log (started with 5.13):
  340. 5.25
  341. Fix memory overflow bug in 5.24.
  342.  
  343. 5.24
  344. Ignore 0x7f and 0x00 pad characters (inserted by some communication systems).
  345.  
  346. 5.22 & .23
  347. Improve analysis of "part" lines to accept form used in bin.pictures group
  348. and by mail server on Garbo.
  349. Fixes a problem with encoded files that use blanks rather than back quotes.
  350.  
  351. 5.20
  352. Z command line option to specify a "cut" line between multiple sections.
  353. Needed if cut line is a valid decodable line (of low probability) which
  354. the user chooses to be intrepreted as a "cut" line.  Plus other improvements
  355. in detecting end of section.
  356.  
  357. 5.16
  358. Encode will split to a minimum of 75 (was 150) lines.
  359. Passes more info to UNARCUUE
  360.  
  361. 5.15
  362. Fixes a problem with trailing blanks on lines.
  363.  
  364. 5.14:
  365. Fixes a minor bug in which a redundant error message was produced when
  366. decoding single section files.
  367.  
  368.  
  369. 5.13 VERSUS 5.10:
  370.  
  371. 5.13 decode has a command line option that disables all interactive
  372. responses to make it more useable from some BBS systems.  Examine the
  373. "y" and "Y" options.
  374.  
  375. 5.13 can increment the number on files up to five digits.  The prior
  376. limit was two digits.  You can now save files with names based on news
  377. article numbers.
  378.  
  379. 5.13 can decode files encoded into 100 or more parts.  A restriction is
  380. that if there are more than 100 parts, the sections MUST be in order.
  381.  
  382.